package com.luke.source.pattern;

import io.netty.buffer.*;
import io.netty.util.ByteProcessor;

/**
 * 迭代器
 */
public class IterableTest {

    public static void main(String[] args) {
        ByteBuf header = Unpooled.wrappedBuffer(new byte[]{1,2,3});
        ByteBuf body = Unpooled.wrappedBuffer(new byte[]{4,5,6});
        ByteBuf merge = merge(header,body);
        //迭代器
        merge.forEachByte(value -> {
            System.out.println(value);
            return true;
        });
    }

    /***
     * 零拷贝
     * @param header
     * @param body
     * @return
     */
    public static ByteBuf merge(ByteBuf header,ByteBuf body){
        CompositeByteBuf byteBuf = ByteBufAllocator.DEFAULT.compositeBuffer(2);
        byteBuf.addComponent(true,header);
        byteBuf.addComponent(true,body);
        return byteBuf;
    }

}
